import {
  Controller,
  Delete,
  Post,
  Query,
  Req,
  UploadedFile,
  UseInterceptors,
} from '@nestjs/common';
import { FileInterceptor } from '@nestjs/platform-express';
import { UploadService } from './upload.service';
import { ApiOperation } from '@nestjs/swagger';

@Controller('files')
export class UploadController {
  constructor(private readonly uploadService: UploadService) {}

  @Post()
  @ApiOperation({ summary: '文件上传' })
  @UseInterceptors(FileInterceptor('file'))
  upload(@UploadedFile() file) {
    return this.uploadService.upload(file);
  }

  @Delete()
  @ApiOperation({ summary: '文件删除' })
  remove(@Query() query: { filePath: string }) {
    return this.uploadService.remove(query);
  }

  @Post('test')
  @ApiOperation({ summary: '测试-内部文件上传' })
  @UseInterceptors(FileInterceptor('file'))
  test(@UploadedFile() file) {
    return file;
  }

  @Post('minio')
  @ApiOperation({ summary: '测试-minio文件上传' })
  minio(@Req() req) {
    return req.uploadedFile;
  }
}
